
package com.webmarmun;

import java.awt.Component;
import java.awt.Image;
import java.awt.Toolkit;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.JOptionPane;


public class Cene extends javax.swing.JFrame {
   public String serverName = "localhost";
    public String mydatabase = "porotnici";
    public String url = "jdbc:mysql://" + serverName + "/" + mydatabase + "?useUnicode=true&characterEncoding=utf8";
    public String username = "root";
    public String password = "";
   
  
    public Cene() {
    float rsq = 0;
    float prev = 0;
    float pau = 0;
        initComponents();
        java.net.URL url1 = ClassLoader.getSystemResource("com/webmarmun/camera.png");
        Toolkit kit = Toolkit.getDefaultToolkit();
        Image img = kit.createImage(url);
        this.setIconImage(img);
         try {

            java.sql.Connection connection = null;
            connection = DriverManager.getConnection(url, username, password);

            java.sql.PreparedStatement t = connection.prepareStatement("SELECT * from fiksno");
            ResultSet trs = null;
            trs = t.executeQuery();
            while (trs.next()) {
                rsq = trs.getFloat("radni_sat");
                prev = trs.getFloat("prevoz");
                pau = trs.getFloat("pausalno");
            }
            radnisat.setText(Float.toString(rsq));
           
            prevoz.setText(Float.toString(prev));
            pausalno.setText(Float.toString(pau));

           

        } catch (SQLException ex) {
            Logger.getLogger(Izmena.class.getName()).log(Level.SEVERE, null, ex);
        }



    }

    
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jPanel1 = new javax.swing.JPanel();
        jLabel1 = new javax.swing.JLabel();
        jLabel2 = new javax.swing.JLabel();
        radnisat = new javax.swing.JTextField();
        jLabel3 = new javax.swing.JLabel();
        prevoz = new javax.swing.JTextField();
        pausalno = new javax.swing.JTextField();
        jLabel4 = new javax.swing.JLabel();
        jButton1 = new javax.swing.JButton();
        jButton2 = new javax.swing.JButton();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);

        jPanel1.setLayout(new org.netbeans.lib.awtextra.AbsoluteLayout());

        jLabel1.setFont(new java.awt.Font("Tahoma", 0, 18)); // NOI18N
        jLabel1.setText("Измена цена:");
        jPanel1.add(jLabel1, new org.netbeans.lib.awtextra.AbsoluteConstraints(10, 11, -1, -1));

        jLabel2.setText("Цена радног сата:");
        jPanel1.add(jLabel2, new org.netbeans.lib.awtextra.AbsoluteConstraints(50, 80, -1, -1));
        jPanel1.add(radnisat, new org.netbeans.lib.awtextra.AbsoluteConstraints(250, 70, 100, 30));

        jLabel3.setText("Цена превоза:");
        jPanel1.add(jLabel3, new org.netbeans.lib.awtextra.AbsoluteConstraints(50, 150, -1, -1));
        jPanel1.add(prevoz, new org.netbeans.lib.awtextra.AbsoluteConstraints(250, 140, 100, 30));
        jPanel1.add(pausalno, new org.netbeans.lib.awtextra.AbsoluteConstraints(250, 230, 100, 30));

        jLabel4.setText("Цена паушала:");
        jPanel1.add(jLabel4, new org.netbeans.lib.awtextra.AbsoluteConstraints(50, 240, -1, -1));

        jButton1.setBackground(new java.awt.Color(102, 255, 102));
        jButton1.setText("Сними");
        jButton1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton1ActionPerformed(evt);
            }
        });
        jPanel1.add(jButton1, new org.netbeans.lib.awtextra.AbsoluteConstraints(253, 330, 90, 40));

        jButton2.setBackground(new java.awt.Color(255, 51, 51));
        jButton2.setText("Одустани");
        jButton2.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton2ActionPerformed(evt);
            }
        });
        jPanel1.add(jButton2, new org.netbeans.lib.awtextra.AbsoluteConstraints(120, 330, -1, 40));

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGap(20, 20, 20)
                .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, 407, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(25, Short.MAX_VALUE))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGap(23, 23, 23)
                .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, 409, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(40, Short.MAX_VALUE))
        );

        java.awt.Dimension screenSize = java.awt.Toolkit.getDefaultToolkit().getScreenSize();
        setBounds((screenSize.width-468)/2, (screenSize.height-508)/2, 468, 508);
    }// </editor-fold>//GEN-END:initComponents

    private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton2ActionPerformed
       this.dispose();
    }//GEN-LAST:event_jButton2ActionPerformed

    private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed
        Component frame1 = null;
        if(radnisat.getText().length() == 0 || prevoz.getText().length() == 0 || pausalno.getText().length() == 0){
              JOptionPane.showMessageDialog(frame1, "Грешка !\n Морате попунити сва поља !", "Први основни суд у Београду", JOptionPane.WARNING_MESSAGE);
        }else{

        try {

            java.sql.Connection connection = null;
            connection = DriverManager.getConnection(url, username, password);

            java.sql.PreparedStatement t = connection.prepareStatement("INSERT INTO fiksno(radni_sat,prevoz,pausalno)values(?,?,?)");
            t.setFloat(1,Float.parseFloat(radnisat.getText().toString()));
            t.setFloat(2,Float.parseFloat(prevoz.getText().toString()));
             t.setFloat(3,Float.parseFloat(pausalno.getText().toString()));
            t.executeUpdate();
            this.dispose();





        } catch (SQLException ex) {
            Logger.getLogger(Izmena.class.getName()).log(Level.SEVERE, null, ex);
        }
        }
    }//GEN-LAST:event_jButton1ActionPerformed

    /**
    * @param args the command line arguments
    */
    public static void main(String args[]) {
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new Cene().setVisible(true);
            }
        });
    }

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton jButton1;
    private javax.swing.JButton jButton2;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JTextField pausalno;
    private javax.swing.JTextField prevoz;
    private javax.swing.JTextField radnisat;
    // End of variables declaration//GEN-END:variables

}
